package com.xyp.a_demo;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/8/5
 * @Desc 从想做到能做
 */
class MyLock {
    public static Object LEFT = new Object();
    public static Object RIGHT = new Object();

}

public class Demo2 {
    public static void main(String[] args) {

        new Thread(){
            @Override
            public void run() {
                synchronized (MyLock.LEFT){
                    System.out.println("女朋友拿到左筷子" );
                    synchronized (MyLock.RIGHT){
                        System.out.println("女朋友拿到右筷子-吃饭" );
                    }
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                synchronized (MyLock.RIGHT){
                    System.out.println("男朋友拿到右筷子" );
                    synchronized (MyLock.LEFT){
                        System.out.println("男朋友拿到左筷子-吃饭" );
                    }
                }
            }
        }.start();

    }
}
